package com.zou.practice.callback;

import java.util.ArrayList;
import java.util.List;

/**
 * @author zouyaowen
 * @date 2020-08-19
 */
public class Broadcaster {

    private final List<Listener> listeners = new ArrayList<>();

    public void register(Listener listener) {
        listeners.add(listener);
    }

    public void unregister(Listener listener) {
        listeners.remove(listener);
    }

    public void broadcast(Object arg) {
        for (Listener listener : listeners) {
            listener.callBack(arg);
        }
    }
}